﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SHKF.B2C.JuShuiTan.Model;
using SHKF.B2C.JuShuiTan.Model.Inter.OrdersQuery;
using SHKF.B2C.JuShuiTan.Model.Inter.TaoBao;
using SHKF.B2C.JuShuiTan.Network;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SHKF.B2C.JuShuiTan.Service.Controllers
{
    /// <summary>
    /// 定单
    /// </summary>
    [Route("[controller]")]
    [ApiController]
    public class OrderController : BaseController
    {
  
        public OrderController(IServiceProvider serviceProvider,ILogger<OrderController> logger) : base(serviceProvider,logger)
        {
           
        }

        /// <summary>
        /// 获取线上出库订单
        /// </summary>
        /// <param name="singleParam"></param>
        /// <returns></returns>
        [HttpPost("List")]
        public async Task<OrderDto> List(OrdersSingleParam singleParam)
        { 
            OrderDto dto = new OrderDto();
            try
            {

                BaseDto dto2 = this.GetCompanyID();
                if (dto2.code == -1)
                {
                    dto = new OrderDto();
                    dto.code = -1;
                    dto.msg = dto2.msg;

                    return dto;
                }
                else
                {
                    this.httpClient.CompanyID = dto2.msg;
                }
                 
                dto = await this.httpClient.OrderQeury(singleParam); 
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex.Message);
            }

            return dto;
        }

        [HttpGet("List/TaoBao")]
        public async Task<OrderListDto> TaoBaoList()
        {
            OrderListDto dto = new OrderListDto();
            try
            {
                //string result = new TaoBaoClient().GetOrderList();

                dto = await this.httpClient.TaoBaoOrderQeury(1,3, DateTime.Parse("2023-03-22 00:00:00"), DateTime.Parse("2023-03-22 23:59:59"));
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex.Message);
            }

            return dto;
        }
    }
}
